package com.bocai.yuweiwangluo.activity;


import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import com.bocai.yuweiwangluo.R;
import com.bocai.yuweiwangluo.View.XListView;
import com.bocai.yuweiwangluo.base.BaseActivity;
import com.bocai.yuweiwangluo.bean.MessageListBean;
import com.bocai.yuweiwangluo.presenter.MessageYesListPresenter;
import com.bocai.yuweiwangluo.viewModel.IMessageYesListView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

/**
 * 消息中心界面
 */
public class MessageYesCenterActivity extends BaseActivity implements View.OnClickListener,XListView.IXListViewListener,IMessageYesListView,AdapterView.OnItemClickListener
{
    @ViewInject(R.id.lv_message_list)
    XListView lv_message_list;
    @ViewInject(R.id.ll_nocotent)
    LinearLayout llnoContent;
    @ViewInject(R.id.ll_refresh)
    LinearLayout llRefresh;
    private int page=1;
    private MessageYesListPresenter messageYesListPresenter;
    @Override
    protected int contentView()
    {
        return R.layout.activity_messagecenter_new;
    }

    @Override
    protected void setData()
    {
        ViewUtils.inject(this);
        initToolbar("已读消息");
        getMessageYesListPresenter();
        getData();
        initEvent();

    }

    private void getData() {
        messageYesListPresenter.getMessage(page + "");
    }

    @Override
    protected void initEvent()
    {
        llRefresh.setOnClickListener(this);
        lv_message_list.setPullLoadEnable(true);
        lv_message_list.setPullRefreshEnable(true);
        lv_message_list.setXListViewListener(this);
        lv_message_list.setOnItemClickListener(this);
    }



    @Override
    public void onClick(View v)
    {
        switch (v.getId())
        {
            case R.id.ll_refresh:
                llRefresh.setVisibility(View.GONE);
                onRefresh();
                break;
        }
    }

    @Override
    public void onRefresh() {
        page=1;
        lv_message_list.setPullLoadEnable(true);
        messageYesListPresenter.getMessage(page+"");
    }

    @Override
    public void onLoadMore() {
        page++;
        messageYesListPresenter.getMessage(page+"");
    }

    @Override
    public int getmyPage() {
        return page;
    }

    @Override
    public void setMyPage(int page) {

    }

    @Override
    public void onLoad() {
        lv_message_list.stopRefresh();
        lv_message_list.stopLoadMore();
        lv_message_list.setRefreshTime("");
    }

    @Override
    public LinearLayout getNoContent() {
        return llnoContent;
    }

    @Override
    public XListView getListView() {
        return lv_message_list;
    }

    @Override
    public MessageYesListPresenter getMessageYesListPresenter() {
        messageYesListPresenter=new MessageYesListPresenter(this,this,this);
        return messageYesListPresenter;
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public LinearLayout getllRefresh() {
        return llRefresh;
    }


    @Override
    public void finishActivity() {
        this.finish();
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        MessageListBean.DataEntity data= (MessageListBean.DataEntity) parent.getAdapter().getItem(position);
        Intent intent=new Intent(this,MessageDetailActivity.class);
        intent.putExtra("data",data);
        intent.putExtra("what","yes");
        startActivity(intent);

    }
}
